package cc.sunni.neti;

import redis.clients.jedis.Jedis;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author jl
 * @since 2021/2/12 22:02
 */
public class SeckillDemo {
    public static ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 100, 10, TimeUnit.SECONDS, new LinkedBlockingDeque<>());

    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        jedis.select(0); // 使用0号逻辑库
        jedis.set("kill_num", "50"); // 设置描述商品数量50
        jedis.del("kill_user"); // 将以前的抢购成功的用户列表删除
        jedis.close();

        // 模拟1000个用户抢购
        for (int i = 0; i < 1000; i++) {
            pool.execute(new KillTask());
        }
    }
}
